<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>国际原油 — 方案详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
   
    <script type="text/javascript" src="../../js/mui.min.js" ></script>
    <script type="text/javascript" src="../../js/common.js"></script>
    <script src="../../js/common1.js"></script>
    <script src="../../js/jquery-1.11.3.js"></script>
    <script>
    	mui.init();
    	var win=null;  
    	
    	var tranlever=null;
    	mui.plusReady(function(){  
    		
    		
    		win=plus.webview.currentWebview();
    		//初始化监听头部和底部事件
			tzdr.init.initHearListener();
    		//获取当前方案信息   方案ID: win.did
    		var paramUrl={
				url:"../login/login.html"
			}
    		mui.app_request("/user/ftrade/details",{
    			"id":win.did
    		},function(result){
    			
    			if(!mui.isnull(result.data.details)){
    				tranlever=result.data.details.tranLever;
    				queryDetails(result.data.details.id);
    				//获取详细数据
    				setDetails(result.data.details);
    				//获取主力合约
    				mui.each(result.data.details.outDiskVoList,function(i,item){
    					setOutDisks(item);
    					
    					
    				});
    			}  
    			
    		},function(result){
    			mui.toast(result.message);
    			return;
    		},paramUrl);
    		function queryDetails(id){
    			mui.app_request("/user/ftrade/getFstTradeDetail",{id:id},function(res){
    				console.log(JSON.stringify(res));
    				if(!mui.isnull(res.data)){
    					insertDateils(res.data);
    				}
    				
	    		},function(res){
	    			console.log(JSON.stringify(res));
	    		});
    		}
    		
    		function insertDateils(data){
    			for(var i=0;i<data.length;i++){
    				var _data = data[i];
    				$("#historyDetailsTable").append("<tr>"+
    						"<td>"+Number(i+1)+"</td>" +
	    				"<td>"+_data.tradeDate+"</td>" +
						"<td>"+_data.username+"</td>" +
						"<td>"+_data.userNo+"</td>" +
						"<td>"+_data.currencyNo+"</td>" +
						"<td>"+_data.exchangeNo+"</td>" +
						"<td>"+_data.commodityNo+"</td>" +
						"<td>"+Number(_data.buyNum)+"</td>" +
						"<td>"+Number(_data.sellNum)+"</td>" +
						"<td>"+Number(_data.tradePrice)+"</td>" +
						"<td>"+Number(_data.free)+"</td>" +
						"<td>"+_data.orderType+"</td>" +
						"<td>"+_data.orderUserno+"</td>" +
						"<td>"+_data.orderUsername+"</td>" +
						"<td>"+_data.tradeType+"</td>" +
	    			"</tr>");
    			}
    		}
//  		document.getElementById("copyaccount").addEventListener("tap",function(){
//  			var t_text=document.getElementById("trade_account").innerHTML;
////  			copytoClip(t_text);
//  		});
    		
//  		document.getElementById("copypw").addEventListener("tap",function(){
//  			var t_text=document.getElementById("trade_password").innerHTML;
////  			copytoClip(t_text);
//  		});
    		
    		document.getElementById("tran_info").addEventListener("tap",function(){
  				mui.openWindow("../agree/clru.html");
  			});
    		
    		document.getElementById("add_fund").addEventListener("tap",function(){
    			//追加保证金
    			mui.openWindow({
    				url:"add.html",
    				id:"add.html",
    				extras:{
    					did:win.did,businessPageId:'future/DetailCl.html'  
    				}
    			});
    		});
    		//给申请终结方案添加点击事件
    		document.getElementById("endtolist").addEventListener("tap",function(){
    			document.getElementById("endtolist").setAttribute("disabled",true);
		    	//获取当前页面信息
				mui.app_request("/user/getbalancerate",{
					"businessType":2,'couponBusinessType':6
				},function(result){
					document.getElementById("endtolist").removeAttribute("disabled");
					//申请终结方案
	    			mui.openWindow({
	    				url:"end.html",
	    				id:"end.html",
	    				extras:{
	    					did:win.did,rate:result.data.rate,coupons:result.data.coupons,businessType:6,businessPageId:'future/DetailCl.html' 
	    				}
	    			});
				},function(result){
					document.getElementById("endtolist").removeAttribute("disabled");
					mui.toast("系统繁忙，请稍后再试！");
					return;
				},paramUrl);
    		});
    		document.getElementById("immediately").addEventListener("tap",function(){
    			mui.openWindow({
    				url:"../login/operateLogin.html",
    				id:"operateLogin",
    				 extras:{
    				 	name:"123"
    				 }
    			})
    		})
    		var endNum=0;
	    	document.getElementById("historyButton").addEventListener("tap",function(){
	    		if(endNum==1){
	    			setTimeout(function(){
	    				$("#historyButton").removeClass("mui-active");
		    			$("#detailButton").addClass("mui-active");
		    			mui.toast("操盘账户正在开户中，还没有数据可显示哦~");
	    			},10)
	    			return
	    		}else if(endNum==6){
	    			$("#historyButton").attr("href","#item2");
	    		}else if(endNum==5){
	    			setTimeout(function(){
	    				$("#historyButton").removeClass("mui-active");
		    			$("#detailButton").addClass("mui-active");
		    			mui.toast("操盘账户开户失败，无数据显示，去看看其它的吧...");

	    			},10)
	    			return
	    		}else{
	    			setTimeout(function(){
	    				$("#historyButton").removeClass("mui-active");
		    			$("#detailButton").addClass("mui-active");
		    			mui.toast("方案未结算，暂无数据显示...");

	    			},10)
	    			return
	    		}
	    		
	    	})

    	function setDetails(details){
    		document.getElementById("trade_account").innerHTML=details.tranAccount;
    		document.getElementById("trade_password").innerHTML=details.tranPassword;
    		document.getElementById("app_time").innerHTML=tzdr.dateUtil.getFormatDataByLong(details.appTime,"yyyy-MM-dd hh:mm");
    		document.getElementById("tranLever").innerHTML=details.tranLever+"手";
    		document.getElementById("traderBond").innerHTML=tzdr.moneyUtils.formatCurrency(details.traderBond)+"元";
    		if(mui.isnull(details.appendTraderBond)){
    			document.getElementById("appendTraderBond").innerHTML="0元";
    		}else{
    			document.getElementById("appendTraderBond").innerHTML=tzdr.moneyUtils.formatCurrency(details.appendTraderBond)+"元";
    		}
    		document.getElementById("traderTotal").innerHTML=tzdr.moneyUtils.formatCurrency(details.traderTotal)+"美元";
    		document.getElementById("lineLoss").innerHTML=tzdr.moneyUtils.formatCurrency(details.lineLoss)+"美元";
    		if(mui.isnull(details.feeManage)){
    			document.getElementById("feeManage").innerHTML="免费";
    		}else{
    			document.getElementById("feeManage").innerHTML=details.feeManage+"元";
    		}
    		document.getElementById("tranFees").innerHTML=details.tranFees;
    		
    		//显示状态
    		switch (details.stateType){
    			case 1:
    				document.getElementById("opening").style.display="block";
    				endNum=1;
    				/*document.getElementById("todownload").style.display="none";*/
    				break;
    			case 2:
    				document.getElementById("endtolist").style.display="block";
    				document.getElementById("endtolist").innerHTML="方案终结处理中";
    				document.getElementById("endtolist").setAttribute("disabled",true);
    				/*document.getElementById("todownload").style.display="none";*/
    				
    				break;
    			case 3:
    				document.getElementById("endtolist").style.display="block";
    				document.getElementById("endtolist").innerHTML="方案终结处理中";
    				document.getElementById("endtolist").setAttribute("disabled",true);
    				/*document.getElementById("todownload").style.display="none";*/
    				
    				break;
    			case 5:
    				document.getElementById("open_fail").style.display="block";
    				endNum=5;
    				/*document.getElementById("todownload").style.display="none";*/
    				break;
    			case 6:
    				document.getElementById("end").style.display="block";
    				$("#historyButton").removeClass("mui-active");
    				$("#detailButton").text("结算明细");
    				$("#sharePay").css("background-color","#FFDD33");
    				endNum=6;
    				/*document.getElementById("todownload").style.display="none";*/
    				//设置结算信息
    				setEnd_info(details);
    				break;
    			default:
    				document.getElementById("using").style.display="none";
    				document.getElementById("endtolist").style.display="block";
    				document.getElementById("add_fund").style.display="block";
    				document.getElementById("trade_info").style.display="block";
    				/*var obj=document.getElementById("download_bun");
    				tzdr.kuaiqiangshou(obj);*/
    				break;
    		}
    		
    		document.getElementById("immediately").addEventListener("tap",function(){
				var trade_account = document.getElementById("trade_account").innerHTML;
    			var trade_password = document.getElementById("trade_password").innerHTML;
				mui.openWindow({
					url:"../login/operateLogin.html",
					id:"operateLogin",
					 extras:{
					 	name:"123",
					 	trade_account:trade_account,
					 	trade_password:trade_password
					 }
				});
			});
    	};
    	
    	function setEnd_info(details){
    		document.getElementById("end_info").style.display="block";
    		document.getElementById("end_time").innerHTML=tzdr.dateUtil.getFormatDataByLong(details.endtime,"yyyy-MM-dd hh:mm");
    		document.getElementById("tranProfitLoss").innerHTML=tzdr.moneyUtils.formatCurrency(details.tranProfitLoss)+"美元("+tzdr.moneyUtils.formatCurrency(details.tranProfitLoss*details.endParities)+"人民币)";
    		$("#sharehref").val("http://cms.vs.com/uploads/topic/share/share.html?="+tzdr.moneyUtils.formatCurrency(details.tranProfitLoss*details.endParities));
    		if (details.tranProfitLoss<0){
    			document.getElementById("tranProfitLoss").className='dt_m_loss';
    		}
    		document.getElementById("endParities").innerHTML="1美元 = "+details.endParities+"人民币";
    		document.getElementById("tranActualLever").innerHTML=details.tranActualLever+"手";
    		document.getElementById("tranFeesTotal").innerHTML=tzdr.moneyUtils.formatCurrency(details.tranFeesTotal)+"元";
    		if(details.endAmount>=0){
    			document.getElementById("endAmount").innerHTML="+"+tzdr.moneyUtils.formatCurrency(details.endAmount)+"元";
    		}else{
    			document.getElementById("endAmount").innerHTML=tzdr.moneyUtils.formatCurrency(details.endAmount)+"元";
    		}
    		var money1=tzdr.moneyUtils.reverseMoney(document.getElementById("traderBond").innerHTML).toFixed(2) ;
    		var money2=tzdr.moneyUtils.reverseMoney(document.getElementById("appendTraderBond").innerHTML).toFixed(2);
    		var money3=parseFloat(details.tranProfitLoss*details.endParities).toFixed(2);
    		var money4=tzdr.moneyUtils.reverseMoney(document.getElementById("tranFeesTotal").innerHTML).toFixed(2);
    		var all=Number(money1)+Number(money2)+Number(money3)-Number(money4);
    		$(".dt_font").text("结算金额(¥"+all.toFixed(2)+") = 操盘保证金(¥"+money1+") + 追加保证金(¥"+money2+") + 交易盈亏(¥"+money3+") - 交易手续费(¥"+money4+")");
    
    	};
    	
    	function setOutDisks(outDiskList){
    		document.getElementById("mainContract").innerHTML=outDiskList.mainContract;
    		var tradeType="";
    		if(!mui.isnull(outDiskList.tradeType)&&!mui.isnull(tranlever+'')){
    			switch (outDiskList.tradeType){
    				case 0:
    				tradeType="富时A50";
    					break;
    				case 6:
    				tradeType="国际原油";
    					break;
    				case 7:
    				tradeType="恒指期货";
    					break;
    				default:
    					break;
    			}
    			
    		}
    		document.querySelector(".mui-title").innerHTML="方案: "+tradeType+" "+tranlever+"手";
    	};
    	
    	 
		//点击复制方法
		function copytoClip(text){
			if(plus.os.name=="Android"){
				var Context=plus.android.importClass("android.content.Context");
				var main=plus.android.runtimeMainActivity();
				var clip=main.getSystemService(Context.CLIPBOARD_SERVICE);
				plus.android.invoke(clip,"setText",text);   
				mui.toast("复制成功！");
			}else{
				var UIPasteboard=plus.ios.importClass("UIPasteboard");
				var generalPasteboard=UIPasteboard.generalPasteboard();
				generalPasteboard.setValueforPasteboardType(text,"public.utf8-plain-text");
				var value=generalPasteboard.valueForPasteboardType("public.utf8-plain-text");
				mui.toast("复制成功！");
			}
		}
    	});
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">美国轻质原油 — 方案详情</h1>		
		<a href="javascript:void(0);" class="top-tel" id="tran_info">操盘细则</a>
	</header>
<div class="mui-content sc_listdeta" id="listDetails">
		<div  class="mui-slider-indicator mui-segmented-control">
			<a class="mui-control-item mui-active" href="#item1" id="detailButton">方案明细</a>
			<a class="mui-control-item" href="" id="historyButton">历史成交明细</a>
		</div>
	<div id="item1" class="mui-control-content mui-active">	
	<ul class="mui-table-view sc_listtime">
		<li class="mui-table-view-cell">
			<label>投资标的：</label>
			<p>美国轻质原油期货当期主力合约<i id="mainContract">xxx</i></p>
		</li>			
		<li class="mui-table-view-cell">
			<label>交易时间：</label>
			<span>09:05-02:00</span>
		</li>
	</ul>	
	<div class="sc_listopen" id="opening" style="display: none;">开户中</div>
	<div class="sc_listopen" id="using" style="display: none;">操盘中</div>
	<div class="sc_liststatus" id="open_fail" style="display: none;">开户失败</div>
	<div class="sc_liststatus" id="end" style="display: none;">方案已结算</div>
	<ul class="mui-table-view sc_listac" style="display: none;" id="trade_info">
		<li class="mui-table-view-cell">
			<label>操盘账户：</label>
			<span id="trade_account">1000000</span>
			<!--<a href="javascript:void(0);" id="copyaccount">点击复制<img src="../../images/list_01.png"></a>-->
		</li>		
		<li class="mui-table-view-cell">
			<label>操盘密码：</label>
			<span id="trade_password">1000000</span>
<!--			<a href="javascript:void(0);" id="copypw">点击复制<img src="../../images/list_01.png"></a>-->
		</li>
		<button class="mui-btn" id="immediately">立即操盘</button>
	</ul>
	<ul class="mui-table-view sc_listsc">
		<li class="mui-table-view-cell">
			<label>方案申请时间：</label>
			<span id="app_time">2016-01-29 14:49</span>
		</li>			
		<li class="mui-table-view-cell">
			<label>最大持仓手数：</label>
			<span id="tranLever">4手</span>
		</li>	
		<li class="mui-table-view-cell">
			<label>操盘保证金(¥)：</label>
			<span id="traderBond">27,750元</span>
		</li>	
		<li class="mui-table-view-cell">
			<label>追加保证金(¥)：</label>
			<span id="appendTraderBond">0元</span>
			<a href="javascript:void(0);" id="add_fund" style="display: none;"><span class="mui-icon mui-icon-plusempty"></span>追加资金</a>
		</li>	
		<li class="mui-table-view-cell">
			<label>总操盘资金($)：</label>
			<span id="traderTotal">10,750美元</span>
		</li>
		<li class="mui-table-view-cell">
			<label>亏损平仓线($)：</label>
			<span id="lineLoss">10,450美元</span>
		</li>
		<li class="mui-table-view-cell">
			<label>账户管理费(¥)：</label>
			<span id="feeManage">免费</span>
		</li>
		<li class="mui-table-view-cell">
			<label>交易手续费(¥)：</label>
			<span><i id="tranFees">58</i>元/单边</span>
		</li>
	</ul>	
	<div id="end_info" style="display: none;">
		<ul class="mui-table-view dt_money">
			<li class="mui-table-view-cell">
				<label>方案结算时间：</label>
				<span id="end_time">2016-02-08 16:10</span>
			</li>
			<li class="mui-table-view-cell">
				<label>交易盈亏($)：</label>
				<span><b id="tranProfitLoss">-12,000.00美元(72,000人民币)</b></span>
			</li>
			<script type="text/javascript">
				var tP=parseInt($('#tranProfitLoss').text());
				if(tP>=0){
					$('#tranProfitLoss').removeClass().addClass('tPred');
				}else{
					$('#tranProfitLoss').removeClass().addClass('tPgreen');
				}
			</script>
			<li class="mui-table-view-cell">
				<label>美元结算汇率：</label>
				<span id="endParities">1美元 = 6.5327人民币</span>
			</li>
			<li class="mui-table-view-cell">
				<label>交易手数：</label>
				<span id="tranActualLever">10手</span>
			</li>
			<li class="mui-table-view-cell">
				<label>交易手续费(¥)：</label>
				<span id="tranFeesTotal">3,334元</span>
			</li>
		</ul>	
		<ul class="mui-table-view sc_listsc">
			<li class="mui-table-view-cell">
				<label>结算金额(¥)：</label>
				<span id="endAmount">8,355.24元</span>
			</li>
		</ul>
		<p class="dt_font">结算金额(¥) = 操盘保证金(¥) + 追加保证金(¥) + 交易盈亏(¥) - 交易手续费(¥)</p>
	</div>
		<div class="ac_btn">
			<button id="endtolist" class="mui-btn mui-btn-block sc_listbtn" type="button" style="display: none;">申请终结方案</button>								
		</div>
	</div>
	<div id="item2" class="mui-control-content ">
			<table id="historyDetailsTable">
				<thead>
					<tr>
						<td width="50px">序号</td>
						<td width="200px">成交日期</td>
						<td width="100px">客户名称</td>
						<td width="100px">客户号</td>
						<td width="100px">币种</td>
						<td width="100px">交易所</td>
						<td width="80px">品种</td>
						<td width="80px">买</td>
						<td width="80px">卖</td>
						<td width="100px">成交价</td>
						<td width="80px">手续费</td>
						<td width="100px">下单类型</td>
						<td width="100px">下单人编号</td>
						<td width="100px">下单人姓名</td>
						<td width="100px">成交类型</td>
					</tr>
				</thead>
			</table>
		</div>
</body>
</html>